package com.databias.j15.perfmon;


import org.nsclient4j.*;

public class NsClientTest {


	/**
	 * NSClient is a service which monitors all kinds of windows functions.
	 * 
	 * documentation here: http://www.intuitivethot.com/netsaint/readme.html
	 * http://www.javaworld.com/javaworld/jw-09-2005/jw-0919-windowspm.html?page=6
	 * 
	 * To find other performance monitor counters, start/run/perfmon  
	 * Right-click to add a counter and you'll see the full list.
	 * 
	 * Without instance: \<performance object>\<counter name>
     * With instance: \<performance object>(<instance name>)\<counter name>
	 * 
	 * @param args
	 */
	
// arguments are: localhost, "\Processor(_Total)\% Processor Time"
	   public static void main(String[] args) {
		   while (true)
	     try {
	       NSClient4j client = new NSClient4j(args[0]);
	       
	       
			float cpuAvg,cpu, uptime;  
			
			cpuAvg= Float.parseFloat(client.getPerfMonCounter("CPU"));
			System.out.println("Cpu average:"+(int)cpuAvg);
			
			cpu= Float.parseFloat(client.getPerfMonCounter("\\Processor(_Total)\\% Processor Time"));
			System.out.println("Cpu instant"+cpu);
			
			float fileSwitches=Float.parseFloat(client.getPerfMonCounter("\\System\\Context Switches/sec"));
			System.out.println("file switches"+fileSwitches);
	       
	       //client.getPerfMonCounter(arg0)
	       System.out.println("Result:" + client.getPerfMonCounter(args[1]));  // This can get anything
	       
	       System.out.println("Uptime:" + client.getUpTimeDays());
	       System.out.println("Free disk space:" + client.getFreePercentDiskSpace("C:"));
	       
	       
	       Thread.sleep(1000);
	     } catch (NSClient4JException e) {
	       System.err.println("Exception Geting Stat:" + e);
	     }
	     catch (Exception e) {
		       System.err.println("Exception :" + e);
		     }
	   }
	 }

